home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / utils / tlayr10 / tilemain.cpp < prev    next >
C/C++ Source or Header  |  1995-04-19  |  8KB  |  263 lines

  1. // TILE LAYER v1.0
  2. // Main module
  3. // -------------------------------------------------
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. // -------------------------------------------------
  9.  
  10. #include "mouse.h"
  11. #include "graph13h.h"
  12.  
  13. #include "layrglob.h"
  14. #include "basicobj.h"
  15. #include "laystuff.h"
  16.  
  17. // -------------------------------------------------
  18.  
  19. extern "C" void put_arrow(unsigned, unsigned);
  20. extern "C" void xor_rect(unsigned, unsigned, unsigned, unsigned, unsigned );
  21.  
  22. extern char layrfont[1024];
  23.  
  24. void Drawcursor();
  25.  
  26. // -------------------------------------------------
  27.  
  28. // This class contain al the hot_areas of the application
  29. // and react only to the CMD_QUIT command generated by the menu buttons.
  30. // For further information about Class hot_area see file BASICOBJ.H
  31.  
  32. class application: public command_target {
  33.  hot_area_group *application_areas;
  34.  unsigned finished;
  35.  
  36. public:
  37.  application(hot_area **);
  38.  virtual ~application();
  39.  
  40.  virtual void run();
  41.  virtual int handle_command(unsigned );
  42. };
  43.  
  44. // -------------------------------------------------
  45.  
  46. application::application(hot_area **active_areas)
  47. {
  48.  static char logo[]= "\r        Tile Layer v1.0\r"
  49.                        "programmed by: gaggi@cs.unibo.it\r"
  50.                      "\r    Press any key to continue\r";
  51.  
  52.  set_video( MODE_13H );
  53.  CurFont= (char far *)layrfont;
  54.  set_palette( def_palette );
  55.  
  56.  if ( resetmouse() )
  57.     {
  58.      message_Window *heila= new message_Window(0,0, WNDW_DEF | WNDW_CNT,logo);
  59.  
  60.      heila->show_mes();
  61.      delete heila;
  62.  
  63.      finished= 0;
  64.      application_areas= new hot_area_group(active_areas);
  65.      application_areas->draw();
  66.  
  67.      Install_mouse();
  68.      SetDrawProc( Drawcursor );
  69.  
  70.      mouse_cursor( ON );
  71.     }
  72.  else {
  73.        Error(MOUSE_ERR);
  74.        application_areas= NULL;
  75.        finished= 1;
  76.       };
  77. }
  78.  
  79. application::~application()
  80. {
  81.  if ( application_areas ) delete application_areas;
  82.  
  83.  resetmouse();
  84.  set_video( TEXT_MODE );
  85.  
  86.  puts("Thank you for using my software, hope you enjoyed it!\n"
  87.       "Feel free to send any comment or feedback to: gaggi@cs.unibo.it");
  88. }
  89.  
  90. void application::run()
  91. {
  92.  
  93.  while(!finished) application_areas->is_mouse_up();
  94.  
  95. }
  96.  
  97. int application::handle_command(unsigned command)
  98. {
  99.  if (command == CMD_QUIT)
  100.     {
  101.      return finished++;
  102.     };
  103.  
  104.  return -1;
  105. }
  106.  
  107. // -------------------------------------------------
  108.  
  109. unsigned _stklen = 2*1024;
  110. unsigned _heaplen= 5*1024;
  111.  
  112. extern application My_appl;
  113.  
  114. tile_set     *tiles = new tile_set(MAX_WORLD_X + 2, 2);
  115. world_editor *editor= new world_editor(tiles, DEFAULT_BUF_LLENGTH,
  116.                                        DEFAULT_BUF_LINES);
  117.  
  118. hot_area *application_obj[]= {
  119.  
  120.       editor,
  121.       tiles,
  122.  
  123.       // Menu Buttons
  124.       new button(MAX_WORLD_X + 2, 122, "Load TIL", CMD_LOAD_SET   , editor),
  125.       new button(MAX_WORLD_X + 2, 135, "Load WLD", CMD_LOAD_WORLD , editor),
  126.       new button(MAX_WORLD_X + 2, 148, "Save WLD", CMD_SAVE_WORLD , editor),
  127.       new button(MAX_WORLD_X + 2, 161, "WLD Info", CMD_SHOW_INFO  , editor),
  128.       new button(MAX_WORLD_X + 2, 174, "Redim   ", CMD_REDIM_WORLD, editor),
  129.       new button(MAX_WORLD_X + 2, 187, "Quit    ", CMD_QUIT       , &My_appl),
  130.  
  131.       // Scroll of tile set and edit window
  132.       new pan_control(MAX_WORLD_X +  2, 40, tiles, LEFT_PAN ),
  133.       new pan_control(MAX_WORLD_X + 15, 40, tiles, RIGHT_PAN),
  134.  
  135.       new pan_control(MAX_WORLD_X + 25, 70, editor, UP_PAN),
  136.       new pan_control(MAX_WORLD_X + 25, 96, editor, DOWN_PAN),
  137.       new pan_control(MAX_WORLD_X + 12, 83, editor, LEFT_PAN),
  138.       new pan_control(MAX_WORLD_X + 38, 83, editor, RIGHT_PAN),
  139.       (hot_area *)0
  140.                              };
  141.  
  142. application My_appl(application_obj); // Builds the applications object !
  143.  
  144. // -------------------------------------------------
  145.  
  146. void Drawcursor()
  147. // Mouse cursor drawing function
  148. // Very complex to explain! (especially for me :) )
  149. {
  150.  static unsigned char first_time= 1, rect_on= 0;
  151.  static unsigned char cursor_area[68];
  152.  register unsigned MouseX= Mouse.PointX >> 1,
  153.                    MouseY= Mouse.PointY;
  154.  
  155.  asm push bx
  156.  asm push cx
  157.  asm push dx
  158.  
  159.  if (first_time)
  160.     {
  161.      if ( MouseX >= editor->xsize || MouseY >= editor->ysize )
  162.         {                       // The cursor is out of the area
  163.                                 // covered by the edit window
  164.  
  165.          if ( rect_on )         // If there was the rectangle near
  166.             {                   // the cursor ...
  167.              rect_on--;         // ... delete it
  168.              xor_rect(editor->cur_x, editor->cur_y, tiles->tile_x,
  169.                       tiles->tile_y, 0x0F);
  170.  
  171.              editor->cur_x= editor->cur_y= 65535; // Force the drawing
  172.                                                   // of the rectangle when
  173.                                                   // the cursor will be within
  174.                                                   // the edit window
  175.             };
  176.           }
  177.      else { // The cursor is within the area covered by the edit window
  178.  
  179.            unsigned temp_cur_x= MouseX - (MouseX % tiles->tile_x);
  180.            unsigned temp_cur_y= MouseY - (MouseY % tiles->tile_y);
  181.  
  182.            // Adjourn if necessary the rectangle's position
  183.            if ( !rect_on || temp_cur_x != editor->cur_x ||
  184.                 temp_cur_y != editor->cur_y )
  185.               {
  186.                // Delete the previous one if present
  187.                if ( rect_on )
  188.                   xor_rect(editor->cur_x, editor->cur_y, tiles->tile_x,
  189.                            tiles->tile_y, 0x0F);
  190.                else rect_on++;
  191.  
  192.                // Adjourn its coordinates and draw the new one
  193.                xor_rect(editor->cur_x= temp_cur_x, editor->cur_y= temp_cur_y,
  194.                         tiles->tile_x, tiles->tile_y, 0x0F);
  195.               }
  196.           };
  197.  
  198.      // Mouse cursor drawing
  199.      save_area(MouseX, MouseY, 8, 8, (char far *)cursor_area);
  200.      put_arrow(MouseX, MouseY);
  201.      first_time--;
  202.     }
  203.  else {
  204.        put_area(MouseX, MouseY, (char far *)cursor_area);
  205.  
  206.        if ( !Mouse.Cursor && rect_on )
  207.           {
  208.            rect_on--;
  209.            xor_rect(editor->cur_x, editor->cur_y, tiles->tile_x,
  210.                     tiles->tile_y, 0x0F);
  211.           };
  212.  
  213.        first_time++;
  214.       };
  215.  
  216.  asm pop  dx
  217.  asm pop  cx
  218.  asm pop  bx
  219. }
  220.  
  221. // -------------------------------------------------
  222.  
  223. static char *error_messages[]= {
  224.                                 "\rMemory allocation fault\r",
  225.                                 "Unable to open file \r%s\r",
  226.                                 "\rMouse not found ... aborting\r"
  227.                                 "\r   Hit a key to continue\r"
  228.                                };
  229.  
  230. void Error(unsigned err_msg, void *info)
  231. {
  232.  message_Window *err_wnd;
  233.  char buffer[80];
  234.  
  235.  if ( info )
  236.     {
  237.      sprintf(buffer, error_messages[err_msg], info);
  238.      if ( strlen(buffer) > 55 )
  239.         {
  240.          buffer[55]= '\r';
  241.          buffer[56]= 0;
  242.         };
  243.  
  244.      err_wnd= new message_Window(10, 10, WNDW_DEF | WNDW_CNT, buffer);
  245.     }
  246.  else err_wnd= new message_Window(10, 10, WNDW_DEF | WNDW_CNT,
  247.                                   error_messages[err_msg]);
  248.  
  249.  err_wnd->show_mes();
  250.  delete err_wnd;
  251. }
  252.  
  253. // -------------------------------------------------
  254.  
  255. main()          // Here is all the main !!!!
  256. {               // Wow, this is the power of object-oriented programming!
  257.  
  258.  My_appl.run();
  259.  
  260. }
  261.  
  262. // ---------------- End of file ----------------
  263.